/*
 * Copyright 2003-2005 (c) Live Media Pty Ltd. <argot@einet.com.au> 
 *
 * This software is licensed under the Argot Public License 
 * which may be found in the file LICENSE distributed 
 * with this software.
 *
 * More information about this license can be found at
 * http://www.einet.com.au/License
 * 
 * The Developer of this software is Live Media Pty Ltd,
 * PO Box 4591, Melbourne 3001, Australia.  The license is subject 
 * to the law of Victoria, Australia, and subject to exclusive 
 * jurisdiction of the Victorian courts.
 */

using System;
using TypeElement = argot.TypeElement;
using TypeException = argot.TypeException;
using TypeMap = argot.TypeMap;
using TypeInputStream = argot.TypeInputStream;
using TypeOutputStream = argot.TypeOutputStream;
using TypeReader = argot.TypeReader;
using TypeReaderAuto = argot.TypeReaderAuto;
using TypeWriter = argot.TypeWriter;
namespace argot.dictionary
{
	
	public class TypeMapMarshaller 
	:TypeReader, TypeWriter
	{
		
		public virtual System.Object Read(TypeInputStream inStream, TypeElement element)
		{
			TypeReader reader = new TypeReaderAuto(typeof(TypeMap));
			return reader.Read(inStream, element);
		}
		
		public virtual void Write(TypeOutputStream outStream, System.Object o, TypeElement element)
		{
			TypeMap map = (TypeMap) o;
			
			
			// write the length out first.
			outStream.WriteObject("U16", (System.Object) map.Size());
			
			System.Collections.IEnumerator i = map.Iterator;

			while (i.MoveNext())
			{
				int id = ((System.Int32) i.Current);
				System.String name = map.GetName(id);
				TypeElement elem = map.GetStructure(id);
				
				outStream.WriteObject("U16", (System.Object) id);
				outStream.WriteObject("meta.name", name);
				outStream.WriteObject("dictionary.definition", elem);
			}
		}
	}
}